package com.gjy.spring.s11.jdk;

import java.lang.reflect.Method;
import java.lang.reflect.UndeclaredThrowableException;

/**
 * @author 宫静雨
 * @version 1.0
 * @since 2023-12-20 15:46:10
 */
public class $Proxy0 implements S11Jdk.Foo {
    private final S11Jdk.InvocationHandler h;

    public $Proxy0(S11Jdk.InvocationHandler invocationHandler) {
        this.h = invocationHandler;
    }

    @Override
    public void foo() {
        try {
            h.invoke(this, foo, new Object[0]);
        } catch (RuntimeException | Error e) { // 运行时异常
            throw e;
        } catch (Throwable e) {
            throw new UndeclaredThrowableException(e);
        }

    }

    @Override
    public int bar() {
        try {
            return (int) h.invoke(this, bar, new Object[0]);
        } catch (RuntimeException | Error e) { // 运行时异常
            throw e;
        } catch (Throwable e) {
            throw new UndeclaredThrowableException(e);
        }
    }

    static Method foo;
    static Method bar;

    static {
        try {
            foo = S11Jdk.Foo.class.getDeclaredMethod("foo");
            bar = S11Jdk.Foo.class.getDeclaredMethod("bar");
        } catch (NoSuchMethodException e) {
            throw new NoSuchMethodError(e.getMessage());
        }
    }

}
